<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>

<html>
<head>
    <title>登录页</title>
    <%--echart线图、柱状图、饼图等各种图型库 cdn--%>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.3/echarts.min.js"></script>
    <%--jquery cdn--%>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>

信息来源 <select name="sourceId">
        <c:forEach items="${sourceList}" var="s">
            <option value="${s.id}">${s.name}</option>
        </c:forEach>
</select><br>
状态 <input name="status"><br>

<button onclick="zxt()">折线图</button>

<button onclick="bing()">饼图</button>
<button onclick="excel()">导出Excel</button>

<div id="main" style="width: 500px;height: 500px"></div>

</body>

<script>

    function excel() {
        let sourceId = $('[name=sourceId]').val();
        let status = $('[name=status]').val();
        location.href = 'excel.do?sourceId=' + sourceId +'&status=' + status
    }


    function bing() {
        let sourceId = $('[name=sourceId]').val();
        let status = $('[name=status]').val();

        $.ajax({
            url: '/bing.do?sourceId=' + sourceId +'&status=' + status,
            success:function (data) {
                console.log(data)

                var chartDom = document.getElementById('main');
                var myChart = echarts.init(chartDom);
                var option;

                option = {
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        top: '5%',
                        left: 'center'
                    },
                    series: [
                        {
                            name: 'Access From',
                            type: 'pie',
                            radius: ['40%', '70%'],
                            avoidLabelOverlap: false,
                            itemStyle: {
                                borderRadius: 10,
                                borderColor: '#fff',
                                borderWidth: 2
                            },
                            label: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                label: {
                                    show: true,
                                    fontSize: 40,
                                    fontWeight: 'bold'
                                }
                            },
                            labelLine: {
                                show: false
                            },
                            data: data
                        }
                    ]
                };

                option && myChart.setOption(option);




            }


        })
    }


    function zxt() {
        let sourceId = $('[name=sourceId]').val();
        let status = $('[name=status]').val();

        $.ajax({
            url:'/zxt.do?sourceId=' + sourceId +'&status=' + status,
            success:function (data) {

                console.log(data)

                var x= []
                var y= []

                for (let i = 0; i < data.length; i++) {
                    let xdata = data[i].xdata;
                    x.push(xdata);
                    let ydata = data[i].ydata;
                    y.push(ydata);
                }

                var chartDom = document.getElementById('main');
                var myChart = echarts.init(chartDom);
                var option;

                option = {
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: x
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            data: y,
                            type: 'line',
                            areaStyle: {}
                        }
                    ]
                };

                option && myChart.setOption(option);




            }

        })


    }


</script>
</html>